package com.example.testfragment;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

public class homework4Fragment extends Fragment {
    private  Button button;
    private  Button button2;
    private  Button button3;
    public homework4Fragment() {
        super(R.layout.homework4);
    }


    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);


        //打开手机浏览器百度页面
        //打开的按钮
        Button button = getView().findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                //设置动作为android.intent.action.VIEW
                intent.setAction("android.intent.action.VIEW");
                //设置要打开的网址
                intent.setData(Uri.parse("http://WWW.baidu.com"));
                startActivity(intent);
            }
        });

        Button button2 = getView().findViewById(R.id.button2);
        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = getActivity().getPackageManager().getLaunchIntentForPackage("com.tencent.mobileqq");
                startActivity(intent);
            }
        });

        Button button3 = getView().findViewById(R.id.button3);
        button3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = getActivity().getPackageManager().getLaunchIntentForPackage("com.tencent.tmgp.sgame");
                startActivity(intent);
            }
        });
    }
}
